package o;

import com.huawei.appgallery.forum.option.upload.bean.AppUploadRes;
import com.huawei.appgallery.forum.option.upload.bean.UploadHeader;
import com.huawei.appgallery.forum.option.upload.bean.UploadInfo;
import com.huawei.appgallery.forum.option.upload.bean.UploadResult;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import o.bjl.d;
import o.brc.e;
import org.json.JSONArray;
import org.json.JSONObject;

public class bzb {
    private static ExecutorService ˋ = Executors.newFixedThreadPool(5);
    private String ˊ;
    private String ˎ;
    private byl ˏ;
    private boolean ॱ = true;

    public bzb(String str, byl o_byl, int i) {
        this.ˏ = o_byl;
        this.ˎ = String.valueOf(i);
        this.ˊ = str;
    }

    public bzb(String str, byl o_byl, long j) {
        this.ˏ = o_byl;
        this.ˎ = String.valueOf(j);
        this.ˊ = str;
    }

    public fjo<byl> ˊ() {
        final fjx o_fjx = new fjx();
        ˋ.execute(new Runnable(this) {
            final /* synthetic */ bzb ˎ;

            public void run() {
                this.ˎ.ˎ(o_fjx);
            }
        });
        return o_fjx.ॱ();
    }

    private void ˎ(fjx<byl> o_fjx_o_byl) {
        if (this.ˏ.ॱॱ() == 3) {
            try {
                dnw.ˊ(new File(this.ˏ.ˊ()));
            } catch (Exception e) {
                bqx.ॱ("UploadImageTask", "deleteFile exception");
            }
            this.ˏ.ˋ(UUID.randomUUID().toString());
        }
        this.ˏ.ˏ(1);
        if (byz.ˋ(this.ˏ, this.ॱ, this.ˎ)) {
            ˋ(o_fjx_o_byl);
            return;
        }
        ˋ(3, (fjx) o_fjx_o_byl);
        bqx.ॱ("UploadImageTask", "pretreatImage failed");
    }

    private void ˋ(final fjx<byl> o_fjx_o_byl) {
        UploadInfo uploadInfo = new UploadInfo(this.ˏ);
        try {
            JSONArray jSONArray = new JSONArray();
            jSONArray.put(new JSONObject(uploadInfo.toJson()));
            ((brc) fho.ˏ().ˋ("Base").ॱ(brc.class)).ˋ(new byx(dnk.ˏ(jSONArray.toString().getBytes("UTF-8")), this.ˊ), new e<byx, AppUploadRes>(this) {
                final /* synthetic */ bzb ॱ;

                public /* synthetic */ void ˋ(Object obj, Object obj2) {
                    ˏ((byx) obj, (AppUploadRes) obj2);
                }

                public /* synthetic */ void ˏ(Object obj, Object obj2) {
                    ॱ((byx) obj, (AppUploadRes) obj2);
                }

                public void ॱ(byx o_byx, AppUploadRes appUploadRes) {
                }

                public void ˏ(byx o_byx, AppUploadRes appUploadRes) {
                    if (appUploadRes.getResponseCode() == 0 && appUploadRes.getRtnCode_() == 0) {
                        List ˏ = appUploadRes.ˏ();
                        if (CollectCheck.isEmpty(ˏ) || ˏ.get(0) == null) {
                            this.ॱ.ˋ(3, o_fjx_o_byl);
                            bqx.ॱ("UploadImageTask", "no useful upload path");
                            return;
                        }
                        this.ॱ.ˋ((UploadResult) ˏ.get(0), o_fjx_o_byl);
                        return;
                    }
                    this.ॱ.ˋ(3, o_fjx_o_byl);
                    bqx.ॱ("UploadImageTask", "response failed");
                }
            });
        } catch (Exception e) {
            ˋ(3, (fjx) o_fjx_o_byl);
            bqx.ॱ("UploadImageTask", "uploadInfo to json error");
        }
    }

    private void ˋ(UploadResult uploadResult, final fjx<byl> o_fjx_o_byl) {
        this.ˏ.ˏ(uploadResult.ˋ());
        this.ˏ.ʼ(uploadResult.ॱ());
        bjl o_byy = new byy();
        o_byy.ˋ(this.ˏ.ˊ());
        o_byy.ॱ(uploadResult.ॱ());
        List<UploadHeader> ˊ = uploadResult.ˊ();
        List arrayList = new ArrayList();
        for (UploadHeader uploadHeader : ˊ) {
            arrayList.add(new d(uploadHeader.ˎ(), uploadHeader.ॱ()));
        }
        o_byy.ॱ(arrayList);
        bza.ˊ(o_byy, new bjf<bjr>(this) {
            final /* synthetic */ bzb ˊ;

            public void ˋ(bjk<bjr> o_bjk_o_bjr) {
                if (o_bjk_o_bjr == null || !o_bjk_o_bjr.ˋ()) {
                    this.ˊ.ˋ(3, o_fjx_o_byl);
                    bqx.ॱ("UploadImageTask", "upload image failed");
                    return;
                }
                this.ˊ.ˋ(2, o_fjx_o_byl);
            }
        });
    }

    private void ˋ(int i, fjx<byl> o_fjx_o_byl) {
        this.ˏ.ˏ(i);
        o_fjx_o_byl.ॱ(this.ˏ);
    }
}
